<template>
  <!--<el-button @click="testclk">测试</el-button>
      <vxe-grid :columns="tableColumn" :loading="loading" :pager-config="tablePage" sortable :proxy-config="tableProxy" border height="486px" highlight-current-row highlight-hover-row ref="ddlCommonTable" resizable size="mini" stripe :select-config="selectConfig"></vxe-grid>-->

  <rm-layout-top :canDrag=false :splitwidth=0>
      <template v-slot:fix>
          <div class="pagetop" ref="buttondiv">
              <el-scrollbar style="width:100%;height:100%">
                  <table style="width:100%">
                      <tr>
                          <td style="text-align:left" v-for="(item, index) in ButtonLists" :key="index">
                              <el-button :icon="item.icon" :type="(Begincheckmode && (checkmode == '0'? (item.id==11):(item.id==10)))?'310_C':'310'" @click="ClickEvent(item.id)" style="min-width: 90px" :disabled="(item.id == 2||item.id==3||item.id==4)?btndisabled:false">{{ (item.id == 8?checktitle: item.label) + (Buttonkeylist[item.id - 1]?("("+Buttonkeylist[item.id - 1]+")"):"") }}</el-button>
                              <!-- <el-button :icon="SwitchEvent(item, '2')" type="310" >{{ SwitchEvent(item, '3') }}</el-button> -->
                          </td>
                          <td v-if="!!customevent">
                              <el-button :icon="customicon" type="310" style="min-width: 90px" @click="ClickCustomEvent(customevent)">{{ customeventname }}</el-button>
                          </td>
                          <!-- <td>
                              <el-button @click="$refs.rmlabreport.ColelseDataShow?$refs.rmlabreport.ColelseDataShow=false:$refs.rmlabreport.ColelseDataShow=true" icon="el-icon-search" ref="editedit" type="310">查看</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-plus" @click="$refs.rmlabreport.$refs.rmlabresult.ResultAddAsync()" type="310" ref="btnadd" :disabled="btndisabled">新增(F2)</el-button>
                          </td>
                          <td style="text-align:left">
                              <el-button icon="el-icon-delete" @click="$refs.rmlabreport.$refs.rmlabresult.ResultDelAsync()" type="310" ref="btndel" :disabled="btndisabled">删除(F3)</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-document" @click="$refs.rmlabreport.SaveReportandResult(2,$refs.rmlabreport.selectdate,$refs.rmlabreport.rptunitid,'',1)" type="310" :disabled="btndisabled">保存(F6)</el-button>
                          </td>
                          <td style="text-align:left">
                              <el-button icon="el-icon-arrow-left" @click="$refs.rmlabreport.pagebylist?$refs.rmlabreport.SpecnoExchangeByList(0):$refs.rmlabreport.SpecnoExchange(0,0)" type="310">上一个</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-arrow-right" @click="$refs.rmlabreport.pagebylist?$refs.rmlabreport.SpecnoExchangeByList(1):$refs.rmlabreport.SpecnoExchange(1,0)" type="310">下一个</el-button>
                          </td>
                          <td style="text-align:left">
                              <el-button icon="el-icon-printer" @click="$refs.rmlabreport.CheckPrint(1)" type="310">打印(F7)</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-check" @click="$refs.rmlabreport.CheckReport()" type="310">{{ checktitle }}</el-button>
                          </td>
                          <td style="text-align:left">
                              <el-button icon="el-icon-folder-checked" @click="$refs.rmlabreport.CollectDeal()" type="310">核收(F11)</el-button>
                          </td> -->
                          <td style="text-align:left">
                              <el-dropdown trigger="click" class="rmClass" size="mini">
                                  <el-button type="310" :clickDelay="0">
                                      更多操作<i class="el-icon-arrow-down el-icon--right"></i>
                                  </el-button>
                                  <el-dropdown-menu slot="dropdown">
                                      <el-dropdown-item v-for="(item,index) in RightItems" :key="index" @click.native="$refs.rmlabreport.ButtonSwitch(item.menuevent)">{{ item.menuname }}</el-dropdown-item>
                                      <!-- <el-dropdown-item @click.native="$refs.rmlabreport.BeforeUnCheckReport($refs.rmlabreport.exactusernoreport)">解除审核</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.UnCheckUser()">审核者注销</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.BatchCheck()">批次审核</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.ShowTodayDanger()">今日危急值</el-dropdown-item> -->
                                      <!-- <el-dropdown-item @click.native="$refs.rmlabreport.MergeNowPat()">合并当前病人结果</el-dropdown-item> -->
                                      <!-- <el-dropdown-item @click.native="$refs.rmlabreport.InputRechkDetail()">输入复查结果</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.OpenRechkNeed()">标记需复查</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.OpenImageFloat()">显示图像浮动窗口</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.OpenSampleImageFloat()">显示样本图像浮动窗口</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.RePrintBarcode()">补打条码</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.QueryReportLog()">查看日志</el-dropdown-item>

                                      <el-dropdown-item @click.native="$refs.rmlabreport.CheckPrint(2)">报告预览</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.QueryPatCase()">查阅病历</el-dropdown-item>
                                      <el-dropdown-item :disabled="btndisabled" @click.native="$refs.rmlabreport.ClearNoDoItems()">清除未做</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.OpenLIS322()">标本合并(移动)</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.OpenMerge()">单项合并</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.ClearPrintFlag()">清除打印标志</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.SetQcSample()">指定为质控标本</el-dropdown-item>
                                      <el-dropdown-item @click.native="$refs.rmlabreport.OpenConfig()">设置</el-dropdown-item> -->
                                  </el-dropdown-menu>
                              </el-dropdown>
                              <!--<el-button icon="el-icon-lock" type="310" @click="ALLSee()">锁定程序</el-button>-->
                          </td>
                          <td width="800" style="width:800px"></td>
                      </tr>
                  </table>
              </el-scrollbar>
          </div>

      </template>
      <rm_Lab_Report ref="rmlabreport" @initError="initError" @haschange="BtnDisable" @title="CheckTitleChange" @OptionsChange="OptionChange" PRGNO="LIS310"></rm_Lab_Report>
  </rm-layout-top>
</template>
<script>
import { Promise } from "q";
import echarts from "echarts";
export default {
  name: "LIS310",
  data() {
      return {
          btndisabled: false,
          checktitle: "审核",
          signbtnname: "签名",
          Begincheckmode: false,
          checkmode: "0",
          RightItems: [],
          ButtonLists: [],
          loadingflag: true,
          Buttonkeylist: ["", "F2", "F3", "F6", "", "", "F7", "F8", "F11"],
          customicon: "el-icon-thumb",
          customevent: "",
          customeventname: "自定义",
      };
  },
  components: {},
  created() {},
  mounted() {
      // 监听body上的点击
      document.querySelector("body").addEventListener("click", this.closeMenu);
  },
  beforeDestroy() {
      // 移除监听
      document.querySelector("body").removeEventListener("click", this.closeMenu);
  },
  updated() {},
  methods: {
      InitPageData() {},
      ALLSee() {
          // console.log(this.$refs);
      },
      initError() {
          this.$message("未获取到默认报告单元!");
      },
      BtnDisable(val) {
          this.btndisabled = val;
      },
      CheckTitleChange(val) {
          if (this.Begincheckmode) {
              return;
          }
          this.checktitle = val;
          var item = this.ButtonLists.find(item => item.id == 8);
          // console.log("val", val);
          // console.log("item", item);
          if (item) {
              //组件中需要切换按钮名称为签名时
              if (val.indexOf("签名") > -1) this.checktitle = this.signbtnname; // item.label;
              // if (this.checktitle.indexOf(item.label) == -1) {
              //     if (item.hasOwnProperty("othertxt")) this.checktitle = item.label;
              // }
          }
      },
      OptionChange(val) {
          var Option = val.Options;
          if (val.RightItem.length > 0) this.RightItems = val.RightItem;
          //报告处理界面自定义按钮绑定事件
          if (Option.buttoncustomevent) {
              var event = this.RightItems.find((item) => item.menuevent == Option.buttoncustomevent);
              if(event) {
                  //图标未设置的话用初始的
                  if(event.menuicon) this.customicon = event.menuicon;
                  this.customevent = event.menuevent;
                  this.customeventname = event.menuname;
              }
          } else {
              this.customicon = "el-icon-thumb";
              this.customevent = "";
              this.customeventname = "自定义";
          }
          var buttonlstr = "1:查看,2:新增,3:删除,4:保存,5:上一个,6:下一个,7:打印,8:审核,9:核收";
          //var buttonlstr = "4:存,1:看,2:增,3:删,5:Up,6:Down,7:打印报告,8:审核报告,9:条码批量录入";
          if (Option.hasOwnProperty("buttonsortdef") && Option.buttonsortdef) {
              buttonlstr = Option.buttonsortdef;
          }
          var buttonarr = buttonlstr.split(",");
          this.ButtonLists = [];
          if (val.hasOwnProperty("Begincheckmode")) {
              this.Begincheckmode = val.Begincheckmode;
              if (this.Begincheckmode) this.checkmode = val.checkmode;
          }
          if (Option.lisshortcutkeyf2 != "") this.Buttonkeylist[1] = Option.lisshortcutkeyf2;
          if (Option.lisshortcutkeyf3 != "") this.Buttonkeylist[2] = Option.lisshortcutkeyf3;
          if (Option.lisshortcutkeyf6 != "") this.Buttonkeylist[3] = Option.lisshortcutkeyf6;
          if (Option.lisshortcutkeyf7 != "") this.Buttonkeylist[6] = Option.lisshortcutkeyf7;
          if (Option.lisshortcutkeyf8 != "") this.Buttonkeylist[7] = Option.lisshortcutkeyf8;
          if (Option.lisshortcutkeyf11 != "") this.Buttonkeylist[8] = Option.lisshortcutkeyf11;
          for (let i = 0; i < buttonarr.length; i++) {
              var valarr = buttonarr[i].split(":");
              if (valarr[1] != "") {
                  if (valarr[0] != "10" || (valarr[0] == "10" && Option.checkmustsignname == "1")) {
                      if (valarr[1].indexOf("|") > -1) {
                          var labelarr = valarr[1].split("|");
                          this.signbtnname = labelarr[1]; //报告单元设置的签名按钮的名称
                          var rightitem = this.$refs.rmlabreport.RightItem.find(item => item.field == "btnUnSign");
                          if (rightitem) rightitem.label = "解除" + this.signbtnname;
                          if (this.Begincheckmode && val.checkmode == "1") this.checktitle = labelarr[1];
                          else if (this.Begincheckmode && val.checkmode == "0") this.checktitle = labelarr[0];
                          if (val.checkmode == "0") this.ButtonLists.push({ label: labelarr[0], id: valarr[0], icon: this.Switchicon(valarr[0]), othertxt: labelarr[1] });
                          else if (val.checkmode == "1") this.ButtonLists.push({ label: labelarr[1], id: valarr[0], icon: this.Switchicon(valarr[0]), othertxt: labelarr[0] });
                      } else {
                          this.ButtonLists.push({ label: valarr[1], id: valarr[0], icon: this.Switchicon(valarr[0]) });
                      }
                  }
              }
          }
      },
      Switchicon(val) {
          switch (val) {
              case "1":
                  return "el-icon-search";
              case "2":
                  return "el-icon-plus";
              case "3":
                  return "el-icon-delete";
              case "4":
                  return "el-icon-document";
              case "5":
                  return "el-icon-arrow-left";
              case "6":
                  return "el-icon-arrow-right";
              case "7":
                  return "el-icon-printer";
              case "8":
                  return "el-icon-check";
              case "9":
                  return "el-icon-folder-checked";
              case "10":
                  return "el-icon-notebook-1";
              case "11":
                  return "el-icon-notebook-2";
          }
      },
      ClickEvent(id) {
          switch (id) {
              case "1":
                  this.$refs.rmlabreport.ColelseDataShow = !this.$refs.rmlabreport.ColelseDataShow;
                  break;
              case "2":
                  this.$refs.rmlabreport.$refs.rmlabresult.ResultAddAsync();
                  break;
              case "3":
                  this.$refs.rmlabreport.$refs.rmlabresult.ResultDelAsync();
                  break;
              case "4":
                  this.$refs.rmlabreport.SaveReportandResult(2, this.$refs.rmlabreport.selectdate, this.$refs.rmlabreport.rptunitid, "", 1);
                  break;
              case "5":
                  this.$refs.rmlabreport.pagebylist ? this.$refs.rmlabreport.SpecnoExchangeByList(0) : this.$refs.rmlabreport.SpecnoExchange(0, 0);
                  break;
              case "6":
                  this.$refs.rmlabreport.pagebylist ? this.$refs.rmlabreport.SpecnoExchangeByList(1) : this.$refs.rmlabreport.SpecnoExchange(1, 0);
                  break;
              case "7":
                  this.$refs.rmlabreport.CheckPrint(1);
                  break;
              case "8":
                  this.$refs.rmlabreport.CheckReport();
                  break;
              case "9":
                  this.$refs.rmlabreport.CollectDeal();
                  break;
              case "10":
                  this.$refs.rmlabreport.SetCheckMode(1);
                  break;
              case "11":
                  this.$refs.rmlabreport.SetCheckMode(0);
                  break;
          }
      },
      ClickCustomEvent(event) {
          if(event && event != ""){
              this.$refs.rmlabreport.ButtonSwitch(event);
          } else {
              this.$alert("该自定义按钮尚未绑定右键菜单事件，请在报告单元选项2905设置，另外还可在MNG139维护按钮图标！");
          }
      },
      //上方按钮功能
  },
  watch: {},
  // beforeRouteEnter(to, from, next) {
  //     next(vm => {
  //         // 通过 `vm` 访问组件实例
  //         //console.log("vm", vm);
  //         vm.$refs.rmlabreport.RegKeyEvent(vm.$refs.rmlabreport);
  //     });
  // },
  // beforeRouteUpdate(to, from, next) {
  //     console.log("to", to);
  //     console.log("from", from);
  //     console.log("next", next);
  //     next();
  //     this.$refs.rmlabreport.RegKeyEvent(this.$refs.rmlabreport);
  // },
  activated() {
      this.$refs.rmlabreport.RegKeyEvent(this.$refs.rmlabreport);
      this.$tool.statusbarMsg(3, '<span style="color:red;">检验者: ' + this.$refs.rmlabreport.exactusernamereport + '</span><span style="color:red;margin-left:5px">审核者: ' +  (!this.$refs.rmlabreport.Options.replacechkuserno  || !this.$refs.rmlabreport.Options.replacechkusername || !this.$refs.rmlabreport.exactusernamerhk ? this.$refs.rmlabreport.exactusernamerhk : this.$refs.rmlabreport.Options.replacechkusername + '('+this.$refs.rmlabreport.exactusernamerhk+')') + "</span>");
      var getrow = this.$tool.getSession("RptTo");
      if (getrow != null && getrow != "") getrow = JSON.parse(getrow);
      else getrow = "";
      if (getrow != "" && getrow.AddBy410 == "1" && !this.loadingflag && getrow.reportid != this.$refs.rmlabreport.PatientInfo.reportid && !this.loadingflag) {
          getrow.AddBy410 = "0";
          this.$tool.setSession("RptTo", JSON.stringify(getrow));
          this.$refs.rmlabreport.rptunitid = getrow.rptunitid;
          this.$refs.rmlabreport.selectdate = getrow.sampledate + " 00:00:00";

          this.$refs.rmlabreport
              .GetOptions(getrow.rptunitid, "0")
              .then(() => {
                  this.$refs.rmlabreport.pageinitloading = false;
                  this.$refs.rmlabreport.QueryCol();
                  this.$refs.rmlabreport
                      .QueryList(1)
                      .then(() => {
                          this.$refs.rmlabreport.specno = getrow.sampleno;
                          this.$refs.rmlabreport.SpecNoChange();
                      })
                      .catch(e => {
                          console.log("eee", e);
                      });
              })
              .catch(() => {
                  this.$refs.rmlabreport.pageinitloading = false;
                  this.$refs.rmlabreport.$pub.Log("未获取到报告单元对应选项!");
              });
      }

      var pageinfo = this.$tool.getSession("RptPageInfo");
      if (!!pageinfo) {
          var pagearr = JSON.parse(pageinfo);
          //无论是跳转页面时该报告单元是否已打开，都从最后一个里面找
          if (pagearr != null && pagearr.length > 0 && !!pagearr[pagearr.length - 1].exci)
          {
              if(pagearr[pagearr.length - 1].exci == '1'){
                  //已经进来了，就要把exci干掉，不然同时开多个报告单元时会再次跑这里
                  delete pagearr[pagearr.length - 1].exci;
                  this.$tool.setSession("RptPageInfo", JSON.stringify(pagearr));
                  this.$refs.rmlabreport.excInit();
              }
          }
      }

      // if (this.loadingflag) {
      //     var pageinfo = this.$tool.getSession("RptPageInfo");
      //     var pagearr = JSON.parse(pageinfo);
      //     if (pagearr == null) pagearr = [];
      //     if (pagearr.length > 0) {
      //         var pathindex = pagearr.findIndex(item => item.id == this.$route.query.id);
      //         if (pathindex < pagearr.length && pathindex != -1) {
      //             var page = pagearr[pathindex + 1];
      //             if (page) {
      //                 this.$router.push({ path: pagearr[pathindex + 1].path });
      //             }
      //         }
      //     }
      //     this.loadingflag = false;
      // }
  }
};
</script>

<style scoped>
/deep/.disabled-cell {
  background-color: #f7f7f7;
}
/deep/.warn-high {
  background-color: #ffc0c0;
}
/deep/.warn-low {
  background-color: #c0c0ff;
}
/deep/.danger {
  background-color: #ff0000;
}
/deep/.RechkBack {
  background-color: #c0ffc0;
}
/deep/.el-image {
  z-index: 2007;
}
/deep/.vxe-body--row .el-input--small .el-input__inner {
  height: 20px !important;
  line-height: 20px !important;
}
/deep/.middle-left .el-checkbox__input.is-checked + .el-checkbox__label {
  color: red;
}
/deep/.dialogdanger .el-textarea.is-disabled .el-textarea__inner {
  color: red;
}
/deep/.el-message-box__wrapper.msgboxtop {
  z-index: 9999;
}
.menu_style {
  position: absolute;
  width: 150px;
  background-color: #fff;
  border-radius: 2px;
  box-shadow: 2px 2px 14px #d0d0d0;
  z-index: 2008;
}
.menu_style > ul > li {
  text-indent: 25px;
  height: 38px;
  line-height: 38px;
  border-bottom: 1px dashed #f0f0f0;
  cursor: pointer;
}
.menu_style > ul > li:hover {
  background: #e0eeff;
}
.dangerPatInfo tr td:nth-child(even) {
  width: 40px;
  border-bottom: 1px solid black;
}
.block {
  float: left;
  height: 93%;
  z-index: 2007;
  position: relative;
  left: 0;
  top: 0;
}
table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}
table tr td:nth-child(even) {
  text-align: left;
}
table tr td:nth-child(1) {
  width: 80px;
}
.pagetop table tr td {
  width: 80px;
}
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
.pagetop {
  left: 0;
  right: 0;
  height: 36px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 0px #ccc;
  position: absolute;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 20px;
}
.pagebottom {
  width: 100%;
  height: 20px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  position: absolute;
  bottom: 5px;
  font-size: 12px;
}
.middle-center {
  position: absolute;
  height: 100%;
  right: 605px;
  left: 305px;
}

.middle-right {
  position: absolute;
  top: 0;
  bottom: 2px;
  width: 600px;
  right: 0px;
}
.middle-left {
  position: absolute;
  height: 100%;
  width: 300px;
  left: 0px;
  top: 0;
}
/deep/.el-date-editor.el-input {
  width: auto;
}
/deep/.Listclass .vxe-table .col_4 .vxe-cell {
  padding: 0px;
}
/deep/.Listclass .vxe-table .col_5 .vxe-cell {
  padding: 0px;
}
/deep/.Listclass .vxe-table .col_6 .vxe-cell {
  padding: 0px;
}

/deep/.el-scrollbar__wrap {
  overflow: hidden;
}
</style>